package com.jml.装饰模式实现三级缓存.decorator.impl;


import com.jml.装饰模式实现三级缓存.component.ComponentCache;
import com.jml.装饰模式实现三级缓存.component.impl.OneLevelCacheComponent;
import com.jml.装饰模式实现三级缓存.decorator.AbstractDecorator;
import java.util.HashMap;
import java.util.Map;

/**
 * @author:jml
 * @date: 2019/9/9 14:37
 * @description：
 */
public class ThreeDecorator extends AbstractDecorator {

    Map threeRedisCacheMap = new HashMap<>();

    public ThreeDecorator(ComponentCache baseCacheComponent) {
        super(baseCacheComponent);
    }

    @Override
    public Object getCache(String key) {
        System.out.println("》》》调用三级缓存");
        Object threeValue = threeRedisCacheMap.get(key);
        if (threeValue == null) {
            //查一级缓存
            Object value = super.getCache(key);
            if (value != null) {
                threeRedisCacheMap.put(key, value);
                threeValue = value;
            }
        }
        return threeValue;
    }

    @Override
    public void putCache(String key, Object value) {

    }

}
